#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 4e5 + 10;
const int MAXM = MAXN << 1;
const int MOD = 1e9 + 7;

int t, n, k, u, v;

vector<int> g[MAXN];
int deg[MAXN], lay[MAXN];

void clear_graph() {
    for (int i = 1; i <= n; i++) {
        g[i].clear();
        deg[i] = lay[i] = 0;
    }

}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while (t--) {

        cin >> n >> k;
        clear_graph();

        for (int i = 0; i < n - 1;i++) {
            cin >> u >> v;

            g[u].push_back(v);
            g[v].push_back(u);

            deg[u]++, deg[v]++;
        }

        queue<pii> q;

        for (int i = 1; i <= n; i++) {
            if (deg[i] == 1) {
                q.push({ i, 1 });
                lay[i] = 1;
            }
        }

        while (!q.empty()) {
            auto t = q.front();
            q.pop();

            int cur = t.first;
            for (auto v : g[cur]) {
                if (deg[v] != 1) {
                    deg[v]--;
                    if (deg[v] == 1) {
                        lay[v] = lay[cur] + 1;
                        q.push({ v, t.second + 1 });
                    }
                }
            }
        }

        int res = 0;
        for (int i = 1; i <= n; i++)
            if (lay[i] > k)
                res++;
        cout << res << endl;
    }
    return 0;
}